/*
 *  $Id: Delegate.cs 881 2009-11-24 19:51:45Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System;

namespace Ragima {
    public delegate bool ConditionPredicate(AbstractObject caster, Card card);
    public delegate void ConditionAction(AbstractObject caster, Card card);

    /// <summary>
    /// Условие по делегатам (для произвольных условий без создания подклассов)
    /// </summary>
    public class DelegateCondition: Condition {
        private Languages.Phrase _notice;
        private ConditionPredicate _test;
        private ConditionAction _action;

        public DelegateCondition(Languages.Phrase notice, ConditionPredicate test): this(notice, test, null) {}
        public DelegateCondition(Languages.Phrase notice, ConditionPredicate test, ConditionAction action) {
            _notice = notice;
            _test = test;
            _action = action;
        }

        public override bool Test(AbstractObject caster, Card card) {
            return _test != null ? _test(caster, card) : false;
        }

        public override void DoCondition(AbstractObject caster, Card card) {
            if (_action != null) _action(caster, card);
        }

        public override Languages.Phrase Notice {
            get { return _notice; }
        }
    }
}